package cn.bdqn.service.wx.impl;

import cn.bdqn.dao.wx.SignDao;
import cn.bdqn.dao.wx.UserDao;
import cn.bdqn.entity.UserInfo;
import cn.bdqn.service.wx.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ProjectName: ycbdqn
 * @Package: cn.bdqn.service.wx.impl
 * @Author: huat
 * @Date: 2020/3/3 22:54
 * @Version: 1.0
 */
@Service
public class SignServiceImpl implements SignService {
    @Autowired
    private SignDao signDao;
    @Autowired
    UserDao userDao;
    /**
     * 获取广告图片url
     * @return
     */
    @Override
    public String getSignImageUrl() {
        return signDao.getSignImageUrl();
    }
    /**
     * 增加用户通过form表单
     * @param realName 姓名
     * @param phoneNumber 手机号
     * @return
     */
    @Transactional
    @Override
    public boolean addUserByForm(String realName,String phoneNumber) {
        Integer id=userDao.getUserByPhone(phoneNumber);
        int result=0;
        if(null==id){
            result= userDao.addUserByForm(realName,phoneNumber);
        }else{
            UserInfo userInfo=new UserInfo();
            userInfo.setId(id);
            userInfo.setRealName(realName);
            userInfo.setPhoneNumber(phoneNumber);
            result=userDao.updateUserPhone(userInfo);
        }
        return result>0?true:false;
    }
}
